package com.fanhao.dllo.justforyou.adapter;

import android.text.Layout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.fanhao.dllo.justforyou.R;
import com.fanhao.dllo.justforyou.entity.HotPost;
import com.fanhao.dllo.justforyou.entity.NewsCommentHotObject1;
import com.fanhao.dllo.justforyou.view.MyImageView;
import com.fanhao.dllo.justforyou.volley.GetVolleyDatasUtil;
import com.fanhao.dllo.justforyou.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 15/11/6.
 */
public class NewsCommentHotViewAdapter extends BaseAdapter {
    private MyImageView imgIv;
    private TextView nameTv, timeTv, likeTv, contentTv;


    private List<HotPost> hotPosts;

    private int position;

    public void addData(List<HotPost> datas) {
        this.hotPosts = datas;
        notifyDataSetChanged();
    }

    /****
     * 根据数据集合个数返回
     * 控制item条数 即控制列表个数
     ***/
    @Override
    public int getCount() {
        return hotPosts != null && hotPosts.size() > 0 ? hotPosts.size() : 0;
    }

    /**
     * 返回当前下标对应的数据
     ***/
    @Override
    public Object getItem(int position) {
        return null;
    }

    /**
     * 返回当前下标对应的id
     ***/
    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            // 获得行布局加载器
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            // 进行行布局加载
            convertView = inflater.inflate(R.layout.activity_news_comment_item_hot, null);
        }

        imgIv = (MyImageView) convertView.findViewById(R.id.imgIv);
        nameTv = (TextView) convertView.findViewById(R.id.nameTv);
        timeTv = (TextView) convertView.findViewById(R.id.timeTv);
        likeTv = (TextView) convertView.findViewById(R.id.likeTv);
        contentTv = (TextView) convertView.findViewById(R.id.contentTv);

        if (hotPosts != null && hotPosts.size() > 0) {
            HotPost hotPost = hotPosts.get(position);
            nameTv.setText(hotPost.getF());
            timeTv.setText(hotPost.getT());
            likeTv.setText(hotPost.getV());
            contentTv.setText(hotPost.getB());

            String imgUrl = hotPost.getTimg();
            GetVolleyDatasUtil.getBitmapRequest(imgUrl,imgIv);
        }

        return convertView;
    }






}
